import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { Profile } from './entities/profile.entity'
import { BaseCrudService } from 'src/common/base-crud.service'
import { CreateProfileDto } from './dto/create-profile.dto'
import { UpdateProfileDto } from './dto/update-profile.dto'

@Injectable()
export class ProfilesService extends BaseCrudService<Profile> {
  constructor(
    @InjectRepository(Profile)
    public repo: Repository<Profile>
  ) {
    super(repo)
  }

  async createOneSimple(dto: CreateProfileDto) {
    const newProfile = this.repo.create(dto)
    return await this.repo.save(newProfile)
  }

  async updateOneSimple(id: string, dto: UpdateProfileDto) {
    const profile = await this.repo.findOneOrFail(id)
    const toSave = this.repo.create({ ...profile, ...dto })
    return await this.repo.save(toSave)
  }
}
